/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef KEYBOARD_SERVICE_KEYBOARD_IFACE_H
#define KEYBOARD_SERVICE_KEYBOARD_IFACE_H

#include <string>

namespace SwanLink {
namespace Finance {

#define ERROR_KEYBOARD_DEVICE_NOT_SUPPORTED  -10101	 // 设备不支持
#define ERROR_KEYBOARD_DEVICE_NON_EXISTENT   -10102  // 设备不存在
#define ERROR_KEYBOARD_OPEN_FAIL             -10104  // 设备打开失败
#define ERROR_KEYBOARD_KEY_SET               -10105  // KeyID设置错误
#define ERR_GET_SN                           -10106  // 获取SN失败
#define ERR_LOAD_KEY                         -10107  // 更新DES失败
#define ERR_GET_MAC                          -10108  // 获取MAC失败
#define ERR_UPDATE                           -10109  // 更新失败
#define ERR_VALUE                            -10110  // 传入值超出keyid值的范围
#define ERROR_KEYBOARD_DEVICE_NOT_OPEN       -10112  // 设备未打开
#define ERR_KEYBOARD_HW_ERROR                -10113  // 设备硬件故障
#define DEVICE_DISCONNECTED                  -10114  // 设备链接已断开
#define ERR_KEY_VAULE_NULL                   -10115  // KeyVaule 为空
#define ERR_DATA_OUT_OF_RANGE                -10116  // 密码长度设置有误
#define ERR_KEY_ID_OUT_OF_RANGE              -10117  // KeyID超出范围
#define ERR_KEY_TYPE_OUT_OF_RANGE            -10118  // KeyType超出范围
#define ERR_PLAIN_DATA_NULL                  -10119  // plain数据为空
#define ERR_KEY_USER_TYPE_OUT_OF_RANGE       -10120  // user type超出范围
#define ERR_ENCRYPT_DATA_FAIL                -10121  // 加密数据失败
#define ERR_SET_PINLEN_DATA                  -10122  // 设置PIN长度失败
#define ERR_DEVICE_NOT_ACTIVE                -10133  // 设备未激活
#define ERR_DEVICE_ACTIVE_FAIL               -10134  // 设备激活失败
#define ERR_KEYBOARD_INPUT_TIME_OUT          -10135  // 输入超时
#define ERR_KEYBOARD_READKEY_FAILED          -10136  // 读取键值失败
#define ERR_KEYBOARD_READKEY_UNKNOWN         -10137  // 读取到未知键值
#define ERR_KEYBOARD_LENGTH_TOO_SHORT        -10138  // 密码长度过短
#define ERR_KEYBOARD_LENGTH_MECISM           -10139  // 密码长度过长
#define ERR_KEYBOARD_INVALID_KEY             -10140  // 无效字符
#define ERR_KEYBOARD_OUT_OF_RANGE            -10141  // 密码长度超出范围
#define ERR_KEYBOARD_TIME_OUT_OF_RANGE       -10142  // 监听时间设置超出范围
#define ERR_NOT_SUPPORTED_LOAD_MASRTKEYID    -10143  // 当前密码键盘未提供主密钥加载接口
#define ERR_SET_KEYBOARD_SM_FAILE            -10144  // 设置国密失败
#define ERR_GET_DATA_FAIL                    -10145  // 获取加密数据失败
#define ERR_KEYBOARD_INPUT_KEYVALUE_SHORT    -10146 // 凯明阳value输入过短

class PinListener {
 public:
    virtual void OnResult(char data[], int len) = 0;
    virtual void OnFailed(int status, const std::string &err) = 0;
};

typedef enum __KeyType {
    KEY_TYPE_SM4 = 280,
    KEY_TYPE_RSA = 281,
    KEY_TYPE_DES = 285,
}KeyType;

typedef enum __userKeyType {
    USER_KEY_ID_PIN = 260,
    USER_KEY_ID_MAC = 261,
    USER_KEY_ID_DATA = 262,
}userKeyType;

typedef enum __MacAlg {
    // X9.19算法
    ALG_MAC_METHOD_X919_80 = 240,
     // 银联ECB算法
    ALG_MAC_METHOD_ECB = 241,
    ALG_MAC_METHOD_X919_X00 = 242,
    // 中总行扩展算法
    ALG_MAC_METHOD_BOCE = 243,
    // X9.19算法 ,后补 00:
    ALG_MAC_METHOD_X919_00 = 244,
    // 异或后 3DES
    ALG_MAC_METHOD_XOR_3DES = 245,
     // X9.9
    ALG_MAC_METHOD_X99 = 246,
}MacAlg;

typedef enum __TextMode {
    TEXT_MODE_PLAIN = 0, // 明文模式
    TEXT_MODE_ENCRYPT = 1, // 密文模式
}TextMode;

typedef enum __KeyPress {
    KEY_CHAR = 301,
    KEY_SHARP = 302,
    KEY_RETURN = 303,
    KEY_OK,
    KEY_BACKSPACE,
    KEY_CLEAR,
    KEY_UP,
    KEY_DOWN,
    KEY_EXIT,
    KEY_DROP,
}KeyPress;

typedef struct __KeyInfo {
    uint16_t keyID;
    KeyType keyType;
    userKeyType user_key_type;
}KeyInfo;
typedef struct __ListenData {
    char data[32];
    int  len;
    TextMode mode;
}ListenData;

typedef int KeyID;

} // namespace Finance
} // namespace SwanLink

#endif
